//购物车数量
var numberItem = 0;

$(function() {
	scPos();
	// 移动端环境下效果
	if (isMobileBrowser()) {
		goTopFun2();//返回顶部
		gnFun();//移动端底部导航变色
	} else {
		sideNav();
		showCartNums();//显示购物车数量
		goTopFun();//返回顶部
		//右侧扫码关注
		$(".r-fix-box.r-fix-box>ul>li").mouseenter(function () {
			$(this).find(".smgz-pic").show("normal");
		}).mouseleave(function () {
			$(this).find(".smgz-pic").hide();
		});
	}
});

$(window).resize(function() {scPos();});

function scPos() {
	var winW = $(window).height();
	$("#s-car-box-middle").css({"height" : winW-110 + "px","overflow-y" : "auto","overflow-x" : "hidden"});
}

function sideNav() {
	var vBtn = $("#v-nav-first"),
		naxBox = $(".r-fixed-wrap");
	vBtn2 = $("#v-nav-close");
	vBtn.click(function (e) {
		if (!vBtn.hasClass("vBtnCurr")) {
			naxBox.stop().animate({"right": "0"}, 400);
			vBtn.addClass("vBtnCurr");
			$("html").addClass("onScroll");
		} else {
			ccrFun();
		}
		stopFunc(e);
	});
	vBtn2.click(function (e) {
		ccrFun();
		stopFunc(e);
	});

	$("#shopcarthtml .s-car-close").click(function () {
		ccrFun();
	});

	function ccrFun() {
		naxBox.stop().animate({"right": "-279px"}, 400);
		vBtn.removeClass("vBtnCurr");
		$("html").removeClass("onScroll");
	}

	function stopFunc(e) {
		document.all ? event.cancelBubble = true : e.stopPropagation();
	}
}

function goTopFun2() {
	var _gt = $("#goTopBtn2");
	_gt.bind("click", function () {
		$("html,body").animate({"scrollTop": 0}, 500);
	});
	var goTop = function () {
		var sTop = $(document).scrollTop();
		(sTop > 120) ? _gt.fadeIn(50) : _gt.fadeOut(50);
	};
	$(window).bind("scroll", goTop);
}


//删除购物车
function deleteCartId(id,goodsId,type) {
	$.ajax({
		url: "/cart/ajax/delete.json",
		data: {
			"id": id,
			'goodsId': goodsId,
			"type": type
		},
		type: "post",
		dataType: "json",
		cache: false,
		success: function (result) {
			shopCartHtml();
			//显示购物车数量
			showCartNums();
		}
	});
}
//查询购物车列表
function shopCartHtml() {
	$.ajax({
		type: 'get',
		dataType: 'text',
		url: '/cart/ajax/list.html?type=1',
		cache: false,
		success: function (result) {
			$("#shopcarthtml").html(result);
			/*if(isNotEmpty(result)){
			 $("#studulist").removeClass('undis').html(result);
			 }else{
			 $("#nocoursebug").removeClass('undis');
			 }*/
		}
	});
}
//显示购物车数量
function showCartNums() {
	$.ajax({
		url: "/cart/ajax/numbers.json?type=1",
		type: "get",
		dataType: "json",
		success: function (result) {
			if (result.code === 0) {
				numberItem = parseInt(result.data);
				$("#shopCartNum").html(numberItem);

			} else {
				$("#shopCartNum").html(0);
				numberItem = 0;
			}
		}
	});
}
//移动端底部导航变色
function gnFun() {
	$("#gn-ul>li").each(function () {
		var _this = $(this),
			_svg = _this.find("svg"),
			_sFi = _svg.find("path");
		if (_this.hasClass("current")) {
			_sFi.attr("fill", "#d44920");
		} else {
			_sFi.attr("fill", "#333");
		}
	})
}